import { requestAdminList, requestDeletAdmin } from "../API/send";

const actions = {
  //请求

  async requestAdminList({ commit }) {
    let result = await requestAdminList();
    if (result.code === 200) {
      commit("REQUESTADMINLIST", result.data);
    } else {
      return Promise.reject(result.message);
    }
  },

  //删除管理员
  async requestDeletAdmin({ commit }, adminName) {
    let result = await requestDeletAdmin(adminName);
    if (result.code !== 200) {
      return Promise.reject(result.message);
    }
  },
};

const mutations = {
  REQUESTADMINLIST(state, data) {
    state.adminList = data;
  },
};

const getters = {};

const state = () => {
  return {
    adminList: [],
  };
};

const store = {
  actions,
  mutations,
  state,
  getters,
};

export default store;
